import { ref } from 'vue'
import { defineStore } from 'pinia'
import { api } from '@/js/ajax'

const EMPTY = {
  tbUser: {},
  tbUserInfo: {},
  tbRole: {},
  exInfo: {},
}
export const userstore = defineStore('userstore', () => {
  const islogin = ref(false)
  const userinfo = ref(EMPTY)
  const userlogo = ref('')


  const updateUserInfo = cb => {
    api.get('/auth', {}, data => {
      if (data.success) {
        userinfo.value = data.data
        userlogo.value = api.userlogo(data.data.tbUser.uid)
      } else {
        userinfo.value = EMPTY
        userlogo.value = ''
      }
      islogin.value = data.success
      cb(islogin.value)
    })

  }
  return { islogin, userinfo, userlogo, updateUserInfo }
})

